#include "person.h"
#include <QDebug>
#include <QQmlListProperty>>

void Person::printInfo() const noexcept
{
    qDebug() << "name: " << m_name << " " << m_age;
    emit qmlCall("hahaha");
}

void Person::clickDemo() const noexcept
{
    qDebug() << __FUNCTION__ << " QML signal";
}

void Person::countDemo(int count) const noexcept
{
    qDebug() << __FUNCTION__ << " QML signal " << count;
}

void Info::setName(QString name) noexcept
{
    m_name = qMove(name);
    emit nameChanged();
}

QString Info::getName() const noexcept
{
    return m_name;
}

void Info::setAge(quint32 age) noexcept
{
    m_age = age;
    emit ageChanged();
}

quint32 Info::getAge() const noexcept
{
    return m_age;
}

void Info::setDate(QDate date) noexcept
{
    m_date = date;
    emit dateChanged();
}

QDate Info::getDate() const noexcept
{
    return m_date;
}

InfoFor7 *PersonFor7::qmlAttachedProperties(QObject *obj)
{
    return new InfoFor7(obj);
}

QQmlListProperty<GtPerson> GtJob::getStudents() noexcept
{
    return QQmlListProperty<GtPerson>(this, &m_student,
                                      &GtJob::AppendFunction,
                                      &GtJob::CountFunction,
                                      &GtJob::AtFunction,
                                      &GtJob::ClearFunction,
                                      &GtJob::ReplaceFunction,
                                      &GtJob::RemoveLastFunction);
}

GtPerson* GtJob::getSquad() noexcept
{
    qDebug() << "getSquad";
    return &m_squad;
}

void GtJob::setSquad(GtPerson *suqad) noexcept
{
    qDebug() << "setSquad  " << suqad->getName();
    m_squad.setName(suqad->getName());
    m_squad.setAge(suqad->getAge());
    emit squadChanged();
}

//void GtJob::append(GtPerson *student) noexcept
//{
//    m_student.append(student);
//}

void GtJob::AppendFunction(QQmlListProperty<GtPerson> *students, GtPerson *stu) noexcept
{
    static_cast<StudentListType *>(students->data)->append(stu);
}

int GtJob::CountFunction(QQmlListProperty<GtPerson> *students) noexcept
{
    return static_cast<StudentListType *>(students->data)->count();
}

GtPerson *GtJob::AtFunction(QQmlListProperty<GtPerson> *students, int index) noexcept
{
    return static_cast<StudentListType *>(students->data)->at(index);
}

void GtJob::ClearFunction(QQmlListProperty<GtPerson> *students) noexcept
{
    static_cast<StudentListType *>(students->data)->clear();
}

void GtJob::ReplaceFunction(QQmlListProperty<GtPerson> *students, int index, GtPerson *stu) noexcept
{
    static_cast<StudentListType *>(students->data)->replace(index, stu);
}

void GtJob::RemoveLastFunction(QQmlListProperty<GtPerson> *students) noexcept
{
    static_cast<StudentListType *>(students->data)->pop_back();
}

void GtPerson::setName(QString name) noexcept
{
    m_name = name;
}

QString GtPerson::getName() const noexcept
{
    return m_name;
}

void GtPerson::setAge(quint32 age) noexcept
{
    m_age = age;
}

quint32 GtPerson::getAge() const noexcept
{
    return m_age;
}
